package com.guanghua.brick.html.tag;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.guanghua.brick.html.IContent;
import com.guanghua.brick.html.IControl;

public class ContentRefTag extends BodyTagSupport {
	private static Log logger = LogFactory.getLog(ContentRefTag.class);

	public int doEndTag() throws JspException {
		//获取pool，然后获取content,放入父控件
		Map<String, IContent> pool = ContentConfigTag.getContentPool(pageContext.getServletContext());
		logger.trace("content ref id:[" + id + "]");
		IContent content = pool.get(id);
		logger.trace("content ref result:[" + content + "]");
		
		//设置父控件中的content属性
		Tag parent = this.getParent();
		if (parent instanceof IControl && content != null) {
			((IControl)parent).setContent(content);
		}
		
		return BodyTagSupport.EVAL_PAGE;
	}
}
